//star
//星星评分js  2018-01-15
var index = "";
var indexarray = new Array();
var optionindex1 = "";
var optionindex2 = "";
var optionindex3 = "";
var optionindex4 = "";
var optionindex5 = "";
$(document).ready(function () {

    $("#index1").click(function () {
        $(this).toggleClass("clickcss");
        if (optionindex1 == "") {
            optionindex1 = "1";
        } else {
            optionindex1 = "";
        }
    })
    $("#index2").click(function () {
        $(this).toggleClass("clickcss");
        if (optionindex2 == "") {
            optionindex2 = "2";
        } else {
            optionindex2 = "";
        }
    })
    $("#index3").click(function () {
        $(this).toggleClass("clickcss");
        if (optionindex3 == "") {
            optionindex3 = "3";
        } else {
            optionindex3 = "";
        }
    })
    $("#index4").click(function () {
        $(this).toggleClass("clickcss");
        if (optionindex4 == "") {
            optionindex4 = "4";
        } else {
            optionindex4 = "";
        }
    })
    $("#index5").click(function () {
        $(this).toggleClass("clickcss");
        if (optionindex5 == "") {
            optionindex5 = "5";
        } else {
            optionindex5 = "";
        }
    })
    var shouindex = $("#hiddenshowindex").val();
    var showoptionindex = $("#hiddenshowoptionindex").val();
    var indexarray = new Array();
    if (showoptionindex.indexOf(",") >= 0) {
        indexarray = showoptionindex.split(',');
    }
    for (var i = 0; i < indexarray.length; i++) {
        $("#index" + [indexarray[i]]).show();
    }
    var stepW = 30;
    var description = new Array("1分 失望", "2分 不满", "3分 一般", "4分 满意", "5分 惊喜");
    if (shouindex > 0) {
        $(".showb").css({ "width": stepW * shouindex });
        descriptionTemp = description[shouindex - 1];
        $(this).find('a').blur();
        return stopDefault(e);
        return descriptionTemp;
    }
  
    var stars = $(".stars > li");
    var descriptionTemp;
    var option = $(".option");
    $(".showb").css("width", 0);
    stars.each(function (i) {
        $(stars[i]).click(function (e) {
            var n = i + 1;
            index = n;
            $(".showb").css({ "width": stepW * n });
            descriptionTemp = description[i];
            $(this).find('a').blur();
            return stopDefault(e);
            return descriptionTemp;
        });
    });

    stars.each(function (i) {
        $(stars[i]).hover(
            function () {
                $(".description").text(description[i]);
                option.find(".option-con:eq(" + $(this).index() + ")").show().siblings().hide();
                $(".prompt").hide();
            },
            function () {
                if (descriptionTemp != null) {
                    $(".description").text(descriptionTemp);
                } else {
                    $(".description").text(" ");
                    option.find(".option-con").hide();
                    $(".prompt").show();
                }


            }
        );
    });
});
function stopDefault(e) {
    if (e && e.preventDefault)
        e.preventDefault();
    else
        window.event.returnValue = false;
    return false;
};
//提交评论
function Saveevalution() {
    var optionindex = "";
    if (optionindex1 == "1") {
        optionindex = optionindex1 + ",";
    }
    if (optionindex2 == "2") {
        optionindex += optionindex2 + ",";
    }
    if (optionindex3 == "3") {
        optionindex += optionindex3 + ",";
    }
    if (optionindex4 == "4") {
        optionindex += optionindex4 + ",";
    }
    if (optionindex5 == "5") {
        optionindex += optionindex5;
    }
    var memo = $("#elsememo").val();
    var oderid = $("#hiddenOrderId").val();
    var billcode = $("#hiddenBillCode").val();
    if (index == "") {
        layer.msg('请选择星级');
        return false;
    }

    layer.open({
        content: '您确定提交吗？',
        btn: ['确定', '取消'],
        shadeClose: false,
        yes: function () {
            layer.msg("您已确认提交");
            // 发起请求
            $.ajax({
                data: { OrderId: oderid, BillCode: billcode, Star: index, OptionIndex: optionindex, Remark: memo },
                url: '/Order/AddEvaluate',
                type: "POST",
                dataType: "json",
                success: function (result) {
                    if (result.Status) {
                        layer.close(shadeLayerIndex);
                        //提示
                        layer.msg('提交成功');
                        setTimeout(function () {  //使用  setTimeout（）方法设定定时1000毫秒
                            location.reload();
                        }, 1000);
                    } else {
                        layer.msg(result.StatusMessage);
                    }
                },
                error: function (result) {
                },
                beforeSend: function () {
                    // 提交表单时呈现阴影弹窗
                    shadeLayerIndex = layer.msg("提交中...");
                },
                complete: function () {
                    // 服务端返回响应信息时将关闭阴影弹窗
                    layer.close(shadeLayerIndex);
                }
            });   // end ajax
        }, no: function () {
            layer.msg('您选择了取消');
        }
    });
}


function Subscribe(billcode, status) {

    if (status == "已完成") {
        layer.alert("快件已完成，无需订阅！");
        return;
    }
    if (status == "已取消") {
        layer.alert("快件已取消，无需订阅！");
        return;
    }
    layer.open({
        type: 2,
        title: "订阅",
        shadeClose: true,
        shade: 0.8,
        area: ['600px', '400px'],
        content: "/Track/MsgRss?billCode=" + billcode + "&status=" + status
    });
}